package dome4;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 01背包代码测试
 * User: 王圆豪
 * Date: 2024-07-15
 * Time: 22:22
 */
public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Good[] goods = new Good[n];
        for (int i = 0; i < n; i++) {
            goods[i] = new Good(sc.nextInt(), sc.nextInt());
        }
        int max = 0;
        int count = 0;
        int price = 0;
        Arrays.sort(goods);
        for (int i = 0; i < n; i++) {
            count = goods[i].v;
            price = goods[i].price;
            for (int j = i + 1; count <= m && j < n; j++) {
                count += goods[j].v;
                if (count <= m) {
                    price += goods[j].price;
                }
            }
            if (max < price) {
                max = price;
            }
        }
        System.out.println(max);
    }
}
